package flc.ast.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.youth.banner.indicator.RectangleIndicator;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

import flc.ast.AppConfig;
import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.MyBannerAdapter;
import flc.ast.databinding.ActivityRecommendBinding;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.bean.StkResBean;
import stark.common.bean.StkTagResBean;

public class RecommendActivity extends BaseAc<ActivityRecommendBinding> {

    private List<StkResBean> listBanner = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.activity_recommend;
    }

    @Override
    protected void initView() {
        mDataBinding.ivRecommendBack.setOnClickListener(v -> onBackPressed());
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        StkResApi.getTagResourceList(this, AppConfig.RECOMMEND_DATA, StkResApi.createParamMap(0, 20), new IReqRetCallback<List<StkResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkResBean> result) {
                if (success) {
                    if (result != null && result.size() > 0) {
                        listBanner = result;
                        MyBannerAdapter bannerAdapter = new MyBannerAdapter(listBanner, mContext);
                        mDataBinding.banner.setAdapter(bannerAdapter, true);//false不无限循环
                        mDataBinding.banner.setBannerGalleryEffect(0, 40, 20, 0.8f);
                        mDataBinding.banner.isAutoLoop(false);//false不自动轮播
                        //点击监听
                        mDataBinding.banner.setOnBannerListener(new OnBannerListener() {
                            @Override
                            public void OnBannerClick(Object data, int position) {
                                StkResBean bean = listBanner.get(position);
                                WallpaperDetailActivity.wallpaperBean = bean;
                                startActivity(WallpaperDetailActivity.class);
                            }
                        });
                    }
                }
            }
        });
    }

}